﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 图书借阅系统
{
    public partial class 新书登记 : System.Web.UI.Page
    {
        string s = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text.Trim();
            string type = TextBox2.Text.Trim();
            string number = TextBox3.Text.Trim();
            string real = TextBox4.Text.Trim();
            if (name == "" || type == ""||number==""||real=="")
            {
                Label1.Text = "图书信息不能为空！请重新输入！";
            }
            else
            {
                using (SqlConnection con = new SqlConnection(s))
                {
                    con.Open();
                    string str = string.Format("INSERT INTO 图书 VALUES ('{0}','{1}','{2}','{3}')", name,type,number,real);
                    SqlCommand cmd = new SqlCommand(str, con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                TextBox1.Text = "";
                TextBox2.Text = "";
                TextBox3.Text = "";
                TextBox4.Text = "";
                Label1.Text = "添加成功！";
            }
        }
    }
}